#include "qtanimeditor.h"
#include "QtGraphicsScene.h"
#include "QtGraphicsStateView.h"
#include "QtGraphicsStateScene.h"

QtAnimEditor::QtAnimEditor(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
	,mStateView(0)
{
	ui.setupUi(this);

	connect(ui.actionClose, SIGNAL(triggered()), qApp, SLOT(quit()));

	ui.mainToolBar->addAction(ui.actionNew);
	ui.mainToolBar->addAction(ui.actionOpen);
	ui.mainToolBar->addAction(ui.actionSave);
	ui.mainToolBar->addAction(ui.actionSaveAs);
	ui.mainToolBar->addSeparator();
	ui.mainToolBar->addAction(ui.actionCreate);
	ui.mainToolBar->addAction(ui.actionCreateState);
	ui.mainToolBar->addSeparator();
	ui.mainToolBar->addAction(ui.actionDelete);
	ui.mainToolBar->addSeparator();
	ui.mainToolBar->addAction(ui.actionPlay);

	mStateView = new QtGraphicsStateView(this);
	ui.stateDockWidget->setWidget(mStateView);
	connect(ui.actionCreateState, SIGNAL(triggered()), mStateView, SLOT(createState()));
}

QtAnimEditor::~QtAnimEditor()
{

}

void QtAnimEditor::connectScene(QtGraphicsScene* scene)
{
	connect(ui.actionNew, SIGNAL(triggered()), scene, SLOT(newFile()));
	connect(ui.actionOpen, SIGNAL(triggered()), scene, SLOT(openFile()));
	connect(ui.actionSave, SIGNAL(triggered()), scene, SLOT(saveFile()));
	connect(ui.actionSaveAs, SIGNAL(triggered()), scene, SLOT(saveFileAs()));

	connect(ui.actionCreate, SIGNAL(triggered()), scene, SLOT(createItem()));

	connect(ui.actionPlay, SIGNAL(triggered(bool)), scene, SIGNAL(playAnim(bool)));

	connect(scene, SIGNAL(changeProperties(QWidget*)), this, SLOT(changeProperties(QWidget*)));
	connect(scene, SIGNAL(changeStateScene(QtGraphicsStateScene*)), this, SLOT(changeStateScene(QtGraphicsStateScene*)));

}

void QtAnimEditor::changeProperties( QWidget* widget )
{
	ui.propertyDockWidget->setWidget(widget);
}

void QtAnimEditor::changeStateScene(QtGraphicsStateScene *scene)
{
	connect(scene, SIGNAL(changeProperties(QWidget*)), this, SLOT(changeProperties(QWidget*)));
	mStateView->setScene(scene);
	scene->setSceneRect(mStateView->rect());
}
